/*================================================================
*   文件名称：main.cpp
*   创 建 者：yang qiang
*   创建日期：2021年02月22日
*   描    述：
*   Copyright (C) 2021 All rights reserved.
*
* ================================================================*/


#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    /**
     * max sum of the subarray
     * @param arr int整型vector the array
     * @return int整型
     */
    int maxsumofSubarray(vector<int>& arr) {
        // write code here
        int current_sum = 0, maxres = 0;
        int size = arr.size();
        for(int i = 0; i < size; i++){
            current_sum += arr[i];
            if(current_sum < 0){
                current_sum = 0;
            } else{
                if(current_sum > maxres){
                    maxres = current_sum;
                }
            }
        }

        return maxres;
    }
};
